package com.zshan.clinic.web.controller.config;


import com.zshan.clinic.admin.entity.vo.*;
import com.zshan.clinic.admin.service.config.ProjectFeeService;
import com.zshan.clinic.common.response.RestResp;
import com.zshan.clinic.common.util.page.PageInfo;
import com.zshan.clinic.database.model.ClinicDoctorFee;
import com.zshan.clinic.database.model.ClinicProjectFee;
import com.zshan.clinic.web.controller.AbstractController;
import com.zshan.clinic.web.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 项目收费设置
 */
@RestController
@RequestMapping("/project/fee")
public class ProjectFeeController extends AbstractController {




    @Autowired
    private ProjectFeeService projectFeeService;


    /**
     * 门诊：获取医生的停诊状态
     * @return 是否停诊：1是0否  如果是1显示继续接诊如果是0显示暂停接诊
     */
    @GetMapping("/getDoctorMedicalStatus")
    public RestResp<String> getDoctorMedicalStatus() {
        UserInfo userInfo = getUserInfo();
        String isStop = projectFeeService.getDoctorMedicalStatus(userInfo.getClinicId(),userInfo.getEmpId());
        return RestResp.SUCCESS(isStop);
    }

    /**
     * 查询收费项目列表-模板和门诊选择查验项目用
     * @param projectName
     * @return
     */
    @GetMapping("/v2/getFeeStandardList")
    public RestResp<List<ClinicProjectFeeCategoryVo>> getFeeStandardListV2(@RequestParam(name = "projectName", required = false) String projectName) {
        UserInfo userInfo = getUserInfo();
        List<ClinicProjectFeeCategoryVo> feeList = projectFeeService.getFeeStandardListV2(userInfo.getClinicId(),projectName);
        return RestResp.SUCCESS(feeList);
    }

    /**
     * 查询收费项目列表-模板和病历选择项目用
     * @param projectCategory  项目分类;1检查2.检验3.治疗 projectCategoryEnum
     * @param projectType 项目类型;头部CT 如果projectCategory=1取字典中的EXAM_TYPE,projectCategory=2取LAB_TYPE，如果等于3取EXT_TYPE
     * @param projectName
     * @return
     */
    @GetMapping("/getFeeStandardList")
    public RestResp<List<ClinicProjectFeeStandardVo>> getFeeStandardList(@RequestParam(name = "projectCategory", required = false) String projectCategory,
                                                                         @RequestParam(name = "projectType", required = false) String projectType,
                                                                         @RequestParam(name = "projectName", required = false) String projectName) {
        UserInfo userInfo = getUserInfo();
        List<ClinicProjectFeeStandardVo> feeList = projectFeeService.getFeeStandardList(userInfo.getClinicId(),projectCategory,projectType,projectName);
        return RestResp.SUCCESS(feeList);
    }

    /**
     * 查询诊所所有的收费列表-缴费右侧用
     * @param
     * @return
     */
    @GetMapping("/getAllFeeList")
    public RestResp<List<ClinicProjectCategoryVo>> getAllFeeList() {
        UserInfo userInfo = getUserInfo();
        List<ClinicProjectCategoryVo> feeList = projectFeeService.getAllFeeList(userInfo.getClinicId());
        return RestResp.SUCCESS(feeList);
    }

    /**
     * 获取医生下拉框---给医生添加挂号费用
     * @return
     */
    @GetMapping("/getSelectList")
    public RestResp<List<ClinicDoctorSelectVo>> getSelectList() {
        UserInfo userInfo = getUserInfo();
        List<ClinicDoctorSelectVo> doctorList = projectFeeService.getSelectList(userInfo.getClinicId());
        return RestResp.SUCCESS(doctorList);
    }

    /**
     * 查询挂号费列表
     * @param
     * @return
     */
    @GetMapping("/getDoctorFeeList")
    public RestResp<PageInfo<ClinicDoctorFeeVo>> getDoctorFeeList(@RequestParam(name = "doctorName", required = false) String doctorName,
                                                                  @RequestParam(name = "deptId", required = false) Long deptId,
                                                                  @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
                                                                  @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
        UserInfo userInfo = getUserInfo();
        PageInfo<ClinicDoctorFeeVo> feeList = projectFeeService.getDoctorFeeList(userInfo.getClinicId(),doctorName,deptId,pageNo, pageSize);
        return RestResp.SUCCESS(feeList);
    }

    /**
     * 添加挂号费
     * @return
     */
    @PostMapping("/addDoctorFee")
    public RestResp<Void> addDoctorFee(@RequestBody ClinicDoctorFee clinicDoctorFee) {
        UserInfo userInfo = getUserInfo();
        clinicDoctorFee.setCreateUserId(userInfo.getEmpId());
        clinicDoctorFee.setCreateBy(userInfo.getEmpName());
        clinicDoctorFee.setClinicId(userInfo.getClinicId());
        projectFeeService.addDoctorFee(clinicDoctorFee);
        return RestResp.SUCCESS();
    }

    /**
     * 编辑挂号费
     * @return
     */
    @PostMapping("/updateDoctorFee")
    public RestResp<Void> updateDoctorFee(@RequestBody ClinicDoctorFee clinicDoctorFee) {
        UserInfo userInfo = getUserInfo();
        clinicDoctorFee.setUpdateUserId(userInfo.getEmpId());
        clinicDoctorFee.setUpdateBy(userInfo.getEmpName());
        clinicDoctorFee.setClinicId(userInfo.getClinicId());
        projectFeeService.updateDoctorFee(clinicDoctorFee);
        return RestResp.SUCCESS();
    }

    /**
     * 删除挂号费
     * @return
     */
    @PostMapping("/deleteDoctorFee")
    public RestResp<Void> deleteDoctorFee(@RequestBody ClinicDoctorFee clinicDoctorFee) {
        UserInfo userInfo = getUserInfo();
        clinicDoctorFee.setUpdateUserId(userInfo.getEmpId());
        clinicDoctorFee.setUpdateBy(userInfo.getEmpName());
        clinicDoctorFee.setClinicId(userInfo.getClinicId());
        projectFeeService.deleteDoctorFee(clinicDoctorFee);
        return RestResp.SUCCESS();
    }

    /**
     * 启用挂号费
     * @return
     */
    @PostMapping("/enableDoctorFee")
    public RestResp<Void> enableDoctorFee(@RequestBody ClinicDoctorFee clinicDoctorFee) {
        UserInfo userInfo = getUserInfo();
        clinicDoctorFee.setUpdateUserId(userInfo.getEmpId());
        clinicDoctorFee.setUpdateBy(userInfo.getEmpName());
        clinicDoctorFee.setClinicId(userInfo.getClinicId());
        projectFeeService.enableDoctorFee(clinicDoctorFee);
        return RestResp.SUCCESS();
    }

    /**
     * 停用挂号费
     * @return
     */
    @PostMapping("/disableDoctorFee")
    public RestResp<Void> disableDoctorFee(@RequestBody ClinicDoctorFee clinicDoctorFee) {
        UserInfo userInfo = getUserInfo();
        clinicDoctorFee.setUpdateUserId(userInfo.getEmpId());
        clinicDoctorFee.setUpdateBy(userInfo.getEmpName());
        clinicDoctorFee.setClinicId(userInfo.getClinicId());
        projectFeeService.disableDoctorFee(clinicDoctorFee);
        return RestResp.SUCCESS();
    }

    /**
     * 查询项目收费列表
     * @param projectCategory  项目分类;1检查2.检验3.治疗 projectCategoryEnum
     * @param projectType 项目类型;头部CT 如果projectCategory=1取字典中的EXAM_TYPE,projectCategory=2取LAB_TYPE，如果等于3取EXT_TYPE
     * @param projectName
     * @param deptId
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/getProjectFeeList")
    public RestResp<PageInfo<ClinicProjectFeeVo>> getProjectFeeList(@RequestParam(name = "projectCategory", required = false) String projectCategory,
                                                                    @RequestParam(name = "projectType", required = false) String projectType,
                                                                    @RequestParam(name = "projectName", required = false) String projectName,
                                                                    @RequestParam(name = "deptId", required = false) Long deptId,
                                                                    @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
                                                                    @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
        UserInfo userInfo = getUserInfo();
        PageInfo<ClinicProjectFeeVo> feeList = projectFeeService.getProjectFeeList(userInfo.getClinicId(), projectCategory,projectType,projectName,deptId,pageNo, pageSize);
        return RestResp.SUCCESS(feeList);
    }

    /**
     * 添加项目收费
     * @return
     */
    @PostMapping("/addProjectFee")
    public RestResp<Void> addProjectFee(@RequestBody ClinicProjectFee clinicProjectFee) {
        UserInfo userInfo = getUserInfo();
        clinicProjectFee.setCreateUserId(userInfo.getEmpId());
        clinicProjectFee.setCreateBy(userInfo.getEmpName());
        clinicProjectFee.setClinicId(userInfo.getClinicId());
        projectFeeService.addProjectFee(clinicProjectFee);
        return RestResp.SUCCESS();
    }

    /**
     * 编辑项目收费
     * @return
     */
    @PostMapping("/updateProjectFee")
    public RestResp<Void> updateProjectFee(@RequestBody ClinicProjectFee clinicProjectFee) {
        UserInfo userInfo = getUserInfo();
        clinicProjectFee.setUpdateUserId(userInfo.getEmpId());
        clinicProjectFee.setUpdateBy(userInfo.getEmpName());
        clinicProjectFee.setClinicId(userInfo.getClinicId());
        projectFeeService.updateProjectFee(clinicProjectFee);
        return RestResp.SUCCESS();
    }

    /**
     * 删除项目收费
     * @return
     */
    @PostMapping("/deleteProjectFee")
    public RestResp<Void> deleteProjectFee(@RequestBody ClinicProjectFee clinicProjectFee) {
        UserInfo userInfo = getUserInfo();
        clinicProjectFee.setUpdateUserId(userInfo.getEmpId());
        clinicProjectFee.setUpdateBy(userInfo.getEmpName());
        clinicProjectFee.setClinicId(userInfo.getClinicId());
        projectFeeService.deleteProjectFee(clinicProjectFee);
        return RestResp.SUCCESS();
    }

    /**
     * 启用项目收费
     * @return
     */
    @PostMapping("/enableProjectFee")
    public RestResp<Void> enableProjectFee(@RequestBody ClinicProjectFee clinicProjectFee) {
        UserInfo userInfo = getUserInfo();
        clinicProjectFee.setUpdateUserId(userInfo.getEmpId());
        clinicProjectFee.setUpdateBy(userInfo.getEmpName());
        clinicProjectFee.setClinicId(userInfo.getClinicId());
        projectFeeService.enableProjectFee(clinicProjectFee);
        return RestResp.SUCCESS();
    }

    /**
     * 停用项目收费
     * @return
     */
    @PostMapping("/disableProjectFee")
    public RestResp<Void> disableProjectFee(@RequestBody ClinicProjectFee clinicProjectFee) {
        UserInfo userInfo = getUserInfo();
        clinicProjectFee.setUpdateUserId(userInfo.getEmpId());
        clinicProjectFee.setUpdateBy(userInfo.getEmpName());
        clinicProjectFee.setClinicId(userInfo.getClinicId());
        projectFeeService.disableProjectFee(clinicProjectFee);
        return RestResp.SUCCESS();
    }

    /**
     * 门诊：暂停接诊
     * @return
     */
    @PostMapping("/stopReception")
    public RestResp<Void> stopReception() {
        UserInfo userInfo = getUserInfo();
        ClinicDoctorFee clinicDoctorFee = new ClinicDoctorFee();
        clinicDoctorFee.setDoctorId(userInfo.getEmpId());
        clinicDoctorFee.setUpdateUserId(userInfo.getEmpId());
        clinicDoctorFee.setUpdateBy(userInfo.getEmpName());
        clinicDoctorFee.setClinicId(userInfo.getClinicId());
        projectFeeService.stopReception(clinicDoctorFee);
        return RestResp.SUCCESS();
    }

    /**
     * 门诊：恢复接诊
     * @return
     */
    @PostMapping("/resumeReception")
    public RestResp<Void> resumeReception() {
        UserInfo userInfo = getUserInfo();
        ClinicDoctorFee clinicDoctorFee = new ClinicDoctorFee();
        clinicDoctorFee.setDoctorId(userInfo.getEmpId());
        clinicDoctorFee.setCreateUserId(userInfo.getEmpId());
        clinicDoctorFee.setCreateBy(userInfo.getEmpName());
        clinicDoctorFee.setClinicId(userInfo.getClinicId());
        projectFeeService.resumeReception(clinicDoctorFee);
        return RestResp.SUCCESS();
    }
}
